const CompressionPlugin = require('compression-webpack-plugin')
const RenamePlugin = require('./Pulgin/renamePlugin')
// const MyPlugin = require('./myPlugin')
// const myloader = require('./myloader/loader')
const path = require('path')
const prodPlugin = []
if (process.env.NODE_ENV === 'production') {
  prodPlugin.push(
    new CompressionPlugin({
      filename: '[path].gz[query]',
      algorithm: 'gzip',
      test: /\.js$|\.css$|\.html$/,
      threshold: 1024, // 只有大小大于该值的资源会被处理 10240
      minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
      deleteOriginalAssets: false // 删除原文件
    })
  )
}
module.exports = {
  productionSourceMap: false,
  outputDir: 'blogdist',
  css: {
    loaderOptions: {
      scss: {
        prependData: `@import "@/css/comment/base.scss";`
      }
    }
  },
  devServer: {
    proxy: {
      '/api1': {
        // 匹配所有以 '/api1'开头的请求路径
        target: 'https://fanyi-api.baidu.com/api/trans/vip/translate', // 代理目标的基础路径
        changeOrigin: true, //说谎 用于控制请求头的host值
        pathRewrite: { '^/api1': '' },
        ws: true
      }
    }
  },
  configureWebpack: {
    externals: {
      'highlight.js': {
        root: 'highlightJs'
      },
      'video.js': {
        root: 'videojs'
      },
      // 'live2d-vue3': {
      //   root: 'live2d'
      // },
      vue: 'Vue',
      'vue-router': 'VueRouter',
      vuex: 'Vuex',
      axios: 'axios'
      // echarts: 'echarts'
    }
    // plugins: [new RenamePlugin()]
  }
}
